package models

import (
	 _ "github.com/go-sql-driver/mysql"
	"github.com/jinzhu/gorm"
	"spider/common"
	"strings"
)

var G_ormdb *gorm.DB

//数据库初始化
func Connect() {
	var err error
	dbConf:=common.G_config
	dsn := strings.Join([]string{dbConf.UserName, ":", dbConf.Password, "@tcp(",dbConf.Ip, ":", dbConf.Port, ")/", dbConf.DbName, "?charset=utf8"}, "")

	G_ormdb, err = gorm.Open("mysql", dsn)
	if err != nil {
		panic(err)
	}
}